package cn.bellychang.recursion.bobo.cl03AddFirstByTailResursion;

/**
 * @author: bellychang
 * @date: 2020/2/15
 */
public class ArrayUtils {

    public static int sumByRecursion(int[] array) {
        if (array == null) {
            throw new IllegalArgumentException();
        }
        return sumArray(array, 0, 0);
    }

    private static int sumArray(int[] array,int start, int result) {
        if (start == array.length) {
            return result;
        } else {
            return sumArray(array, start + 1, result + array[start]);
        }
    }
}
